package com.wish.group05.base.service.impl;

import com.wish.group05.base.dto.RequestForDownLoadBills;
import com.wish.group05.base.entity.CwLklCheckFile;
import com.wish.group05.base.mapper.CwLklCheckFileMapper;
import com.wish.group05.base.service.ICwLklCheckFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wish.group05.common.security.service.TokenService;
import com.wish.group05.system.api.RemoteDictDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 拉卡拉下载的对账单表 服务实现类
 * </p>
 *
 * @author houzehui
 * @since 2022-05-23
 */
@Slf4j
@Service
public class CwLklCheckFileServiceImpl extends ServiceImpl<CwLklCheckFileMapper, CwLklCheckFile> implements ICwLklCheckFileService {

    @Autowired
    TokenService tokenService;
    @Autowired
    RemoteDictDataService remoteDictDataService;

    @Override
    public String downloadBills(RequestForDownLoadBills downLoadRequest) {
        log.info("downloadBills对账单下载处理 Start...");

        //获取登录对象id
        Long loginUserId = tokenService.getLoginUser().getUserid();
        String billDay = downLoadRequest.getBillDay();
        String billType = downLoadRequest.getBillType();

        if (StringUtils.isNoneBlank(billDay) || StringUtils.isNoneBlank(billType)) {
            // 账单下载批次（由36位UUID组成，分组用，同一个文件批次下载的UUID一样）
            String downloadBatchUuid = UUID.randomUUID().toString();

            int type = Integer.parseInt(billType);

            try {
                log.info("========={}的{}账单开始下载=========",billDay);
                //1.代付 2.认证支付 3.微信 4 支付宝
                if (type == 1) {
                    downLoadDFBill(billDay,loginUserId,downloadBatchUuid);
                }

            } catch (NullPointerException parseException) {
                parseException.printStackTrace();
            } catch (Exception e) {

            }

        }
        return null;
    }

    /**
     * @Description:下载并处理拉卡拉代付对账单
     * @param billDay 账单日期
     * @param downloadBatchUuid
     */
    private void downLoadDFBill(String billDay, Long loginUserId, String downloadBatchUuid) {
        //调用接口，下载代付对账单
        String result = "";
        List<String> list = new ArrayList<>();

    }
}
